﻿Imports System.IO

Imports drawing = System.Drawing
Imports forms = System.Windows.Forms

Partial Public Class Configuration
	Public Sub New()
		InitializeComponent()
		SetToDoFilePathText()
	End Sub

	Private Sub fontColor_Click(ByVal sender As Object, ByVal e As RoutedEventArgs)
		Dim colorDialog = GetColorDialog(My.Settings.FontForeColor)

		If colorDialog.ShowDialog() = Forms.DialogResult.OK Then
			My.Settings.FontForeColor = TranslateColor(colorDialog.Color)
		End If
	End Sub

	Private Sub glowColor_Click(ByVal sender As Object, ByVal e As RoutedEventArgs)
		Dim colorDialog = GetColorDialog(My.Settings.FontGlowColor)

		If colorDialog.ShowDialog() = Forms.DialogResult.OK Then
			My.Settings.FontGlowColor = TranslateColor(colorDialog.Color)
		End If
	End Sub

	Private Sub btnToDoFind_Click(ByVal sender As Object, ByVal e As RoutedEventArgs)
		Dim fileDialog As New forms.OpenFileDialog()

		If fileDialog.ShowDialog() = System.Windows.Forms.DialogResult.OK Then
			Dim fi As New FileInfo(fileDialog.FileName)

			My.Settings.ToDoFileName = fi.Name
			My.Settings.ToDoFilePath = fi.DirectoryName

			SetToDoFilePathText()
		End If
	End Sub

	Private Shared Function GetColorDialog(ByVal color As Color) As Forms.ColorDialog
		Return New Forms.ColorDialog()
	End Function

	Private Shared Function TranslateColor(ByVal value As Drawing.Color) As Color
		Return Color.FromArgb(value.A, value.R, value.G, value.B)
	End Function

	Private Sub SetToDoFilePathText()
		txtToDoFind.Text = Path.Combine(My.Settings.ToDoFilePath, My.Settings.ToDoFileName)
	End Sub


#Region "ok / cancel buttons"

	Private Sub btnhCancel_Click(ByVal sender As Object, ByVal e As RoutedEventArgs)
		btnOk.IsEnabled = False

		My.Settings.Reload()

		DialogResult = False
	End Sub

	Private Sub btnOk_Click(ByVal sender As Object, ByVal e As RoutedEventArgs)
		btnOk.IsEnabled = False

		My.Settings.Save()

		DialogResult = True
	End Sub
#End Region

End Class
